﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Convertor.Interface;
using Wpf.CommonTools.SystemExtension;

namespace Convertor.Plugin.GenerateSequence
{
    [Flags]
    public enum GenerateTypes
    {
        Sequence = 1
    }
    [Serializable]
    public class ConfigContent : IConfigContent, ISerializable, ICloneable, INotifyPropertyChanged
    {
        private GenerateTypes generateType;

        public GenerateTypes GenerateType
        {
            get { return generateType; }
            set { generateType = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("ToolTip")); } }
        }
        private string templateText = "{0}";

        public string TemplateText
        {
            get { return templateText; }
            set { templateText = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("ToolTip")); } }
        }
        private uint? paddingLeftNumber;

        public uint? PaddingLeftNumber
        {
            get { return paddingLeftNumber; }
            set { paddingLeftNumber = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("ToolTip")); } }
        }
        private ulong? startNumber;

        public ulong? StartNumber
        {
            get { return startNumber; }
            set { startNumber = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("ToolTip")); } }
        }
        private ulong? stopNumber;

        public ulong? StopNumber
        {
            get { return stopNumber; }
            set { stopNumber = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("ToolTip")); } }
        }

        public ConfigContent()
        {
        }

        public override string ToString()
        {
            return ToolTip;
        }

        #region IToolTip 成员

        public string ToolTip
        {
            get { return string.Format(UILanguage.TryFindResource("Plugin_GenerateSequence_Info"), this.templateText); }
        }

        #endregion

        #region ISerializable 成员

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("GenerateType", GenerateType, typeof(GenerateTypes));
            info.AddValue("TemplateText", TemplateText, typeof(string));
            info.AddValue("PaddingLeftNumber", PaddingLeftNumber, typeof(uint?));
            info.AddValue("StartNumber", StartNumber, typeof(uint?));
            info.AddValue("StopNumber", StopNumber, typeof(uint?));
        }

        public ConfigContent(SerializationInfo info, StreamingContext context)
        {
            try
            {
                generateType = (GenerateTypes)info.GetValue("GenerateType", typeof(GenerateTypes));
            }
            catch { }
            try
            {
                templateText = (string)info.GetValue("TemplateText", typeof(string));
            }
            catch { }
            try
            {
                paddingLeftNumber = (uint?)info.GetValue("PaddingLeftNumber", typeof(uint?));
            }
            catch { }
            try
            {
                startNumber = (ulong?)info.GetValue("StartNumber", typeof(ulong?));
            }
            catch { }
            try
            {
                stopNumber = (ulong?)info.GetValue("StopNumber", typeof(ulong?));
            }
            catch { }
        }
        #endregion

        #region ICloneable 成员

        public object Clone()
        {
            ConfigContent a = new ConfigContent()
            {
                PaddingLeftNumber = this.PaddingLeftNumber,
                StartNumber = this.StartNumber,
                StopNumber = this.StopNumber,
                TemplateText = this.TemplateText,
                GenerateType = this.GenerateType
            };
            return a;
        }

        #endregion


        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
